<template>
	<div>
		<div style="width: 100%;height: 20px;background-color: #ebedf0;"></div>
		<div class="changewhite" style="padding: 20px;">
			<!--<Row style="margin-top:15px;text-align: left;">   			
		        <Col span="24">
		        	<Card style="width:880px;margin: auto;">
		        		<Spin size="large" fix v-if="loadingShow"></Spin>
		        		<p slot="title" style="text-align:center">
				              	 新增评价计算
				        </p>
				        <Row style="text-align: center;">   			
		        			<Col span="12">
					        	<span>名称：</span>
								<Input v-model="calculationname"  placeholder="请输入评价名称" style="width:200px"></Input>
		        			</Col>	
		        			<Col span="12">
					        	<span>年级：</span>
								<Select :label-in-value=true @on-change="gradechange" v-model="gradeselect" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in gradelist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row v-if="toggleshow[0]" style="margin-top:10px;text-align: center;">   			
		        			<Col span="12">
					        	<span>基数：</span>
								<Select v-model="highBase" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in highBaselist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
		        			<Col span="12">
					        	<span>本次：</span>
								<Select v-model="highThis" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in highThislist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row v-if="toggleshow[1]" style="margin-top:10px;text-align: center;">   			
		        			<Col span="12">
					        	<span>入学考试：</span>
								<Select v-model="midBase" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in midBaselist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
		        			<Col span="12">
					        	<span>本次：</span>
								<Select v-model="midThis" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in midThislist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row v-if="toggleshow[2]" style="margin-top:10px;text-align: center;">   			
		        			<Col span="12">
					        	<span>初一考试：</span>
								<Select v-model="midFirstBase" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in midFirstBaselist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row v-if="toggleshow[3]" style="margin-top:10px;text-align: center;">   			
		        			<Col span="12">
					        	<span>初二考试：</span>
								<Select v-model="midSecondBase" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in midSecondBaselist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row>
					    	<Col span="24" style="margin-top:15px;text-align: center;">
					    		<Button @click="addcalculation" type="primary"  icon="checkmark-round">计算</Button>
					    	</Col>
					    </Row> 
				    </Card>
		        </Col>			        
			</Row>-->
			
			<Row>
	        	<Col span="24" style="text-align: left;margin-top:15px;">
	        		<span>应往届：</span>
			        	<RadioGroup v-model="sessionCode" type="button" @on-change="sessionCodeChange">
			        		<Radio v-for="item in sessionCodeList" :key="item.value" :label="item.value">{{item.label}}</Radio>
				    	</RadioGroup>
				    <!--<Spin size="large" fix v-if="gradelistshow"></Spin>-->
		        </Col>
		    </Row>
			<Row v-if="sessionCode==1?true:false">
	        	<Col span="24" style="text-align: left;margin-top:15px;">
	        		<span>年级筛选：</span>
			        	<RadioGroup v-model="gradeselect1" type="button" @on-change="gradechange1">
			        		<Radio v-for="item in gradelist1" :key="item.value" :label="item.value">{{item.label}}</Radio>
					        
				    	</RadioGroup>
				    <Spin size="large" fix v-if="gradelistshow"></Spin>
		        </Col>
		    </Row>
		    <Row v-if="sessionCode==0?true:false">
	        	<Col span="24" style="text-align: left;margin-top:15px;">
	        		<span>毕业年份：</span>
		        	<Input v-model="graduateYear" style="width: 100px;"   placeholder="请输入毕业年份"  />
		        	<Button @click="getGraduateList" type="primary"  >查询</Button>
		        </Col>
		    </Row>
		    <Row>
		        <Col span="10" style="text-align: left;margin-top:15px;font-size: 18px;">
		        	<span>计算完成列表</span>
		        </Col> 
		        <!--<Col span="14" style="text-align: right;margin-top:15px;font-size: 16px;">
		        	<Button v-if='achievements_query_add'  @click="addcalculation" type="success" size="small"><i class="iconfont alicon-add1"></i></Button>
		        </Col> -->
		    </Row>
			<Row v-if='list.length == 0?true:false'>
		        <Col span="24" style="text-align: center;margin-top:15px;font-size: 14px;">
		        	<span>{{textinfo}}</span>
		        </Col> 
		         
		    </Row>
			
			<div style="position: relative;" class="changegray">
	        	<Row v-for="item in list" :key="item.performanceId" style="margin-top:15px;text-align: left;">   			
			        <Col span="24" >
			        	<Card>
					        <Row >   			
			        			<Col span="24">
						        	{{item.performanceName}}
			        			</Col>			        
							</Row>
							<Row style="margin-top:10px;text-align: left;">   			
			        			<Col span="5">
						        	年段：{{item.gradeName}}
			        			</Col>
			        			<Col span="6">
						        	基数：{{item.baseExamName}}
			        			</Col>
			        			<Col span="6">
						        	本次：{{item.thisExamName}}
			        			</Col>
			        			<Col span="4">
						        	时间：{{item.createTime}}
			        			</Col>
			        			<Col span="3">
			        				<Tooltip content="下载详细数据" theme="light" placement="top">
						        		<Button type="ghost" shape="circle" icon="iconfont alicon-down_light" @click="exportexl(item.performanceId)"></Button>
						        	</Tooltip>
			        				<Tooltip content="查看详细数据" theme="light" placement="top">
						        		<Button type="ghost" shape="circle" icon="ios-keypad" @click="lookdetail(item.performanceId,item.gradeId,item.performanceName,item.gradeName,item.baseExamName,item.thisExamName,item.createTime)"></Button>
						        	</Tooltip>
						        	<Tooltip content="删除此数据" theme="light" placement="top">
						        		<Button type="ghost" shape="circle" icon="trash-a" @click="deldata(item.performanceId)"></Button>
						        	</Tooltip>
			        			</Col>
							</Row>
					    </Card>
			        </Col>	
				</Row> 
				<Spin size="large" fix v-if="listshow"></Spin>
		    </div>
			
			<Page style="text-align: center;margin-top:15px;" :current="current" :total="recordCount" @on-change="pageChange"/>
			
		</div>
	</div>
</template>

<script>
	import api from "@/components/js/Apidomain.js"
	import { setsessionstorage,getsessionstorage } from '@/components/js/Localstorage'
	import { mapMutations } from 'vuex'
	export default{
		data(){
			return{
				loadingShow:false,				//面板菜单获取的加载中显示隐藏
				listshow:false,						//切换评价列表的加载中显示隐藏
				gradelistshow:false,				//控制年级选择框的加载中的显示和隐藏
				
				gradeselectlabel:"",			//年级选择的label值
				
				calculationname:"",			//输入的名称
				gradeselect:"",				//年级选择
				highBase:"",				//高中基数
				highThis:"",				//高中本次
				
				midBase:"",					//初中入学
				midThis:"",					//初中本次
				midFirstBase:"",			//初一下学期期末
				midSecondBase:"",			//初二下学期期末
				
				toggleshow:[],					//切换初中高中的基数成绩输入框
				
				
				
				gradelist: [
//                  {value: '1',label: '高一'},
//                  {value: '2',label: '初一'},
//                  {value: '3',label: '初二'},
//                  {value: '4',label: '初三'},
                ],
                highBaselist:[],
                highThislist:[],
                midBaselist:[],
                midThislist:[],
                midFirstBaselist:[],
                midSecondBaselist:[],
                
                
                //下面列表的数据
                list:[
//					{"id":110,"name":"2018年期末考评价计算","grade":"高二年级","cardinalNumber":"2017年期末考试","thisTime":"2018年期末考试","time":"2018-07-23"},
//					{"id":111,"name":"2018年期末考评价计算","grade":"高二年级","cardinalNumber":"2017年期末考试","thisTime":"2018年期末考试","time":"2018-07-23"},
				],
				gradeselect1:"",
				gradelist1: [
//					{value: '1',label: '全部'},{value: '2',label: '初一'},{value: '3',label: '初二'},{value: '4',label: '初三'},{value: '5',label: '高一'},{value: '6',label: '高二'},{value: '7',label: '高三'}, 
                ],
                textinfo:'请选择或输入参数',						//没有数据的时候显示
                
                sessionCode:"1",				//应往届
				sessionCodeList:[			//应往届选择项
					{value:"1",label: '应届'},
					{value:"0",label: '往届'}
				],
				recordCount:0,				//总条数
				
				current:1,					//页码
				graduateYear:"",			//毕业年份
			}
		},
		created(){
			this.getgradelist();
			this.getgradelist1();
		},
		methods:{
			...mapMutations([
				"SAVE_EXCEL_NAME"
			]),
			chance:function(){
				this.$emit('chance')
			},
			gradechange:function(value){
				this.gradeselectlabel = value.label;
				if(value.label.indexOf("高") > -1){
					this.toggleshow = [true,false,false,false]
				}
				if(value.label.indexOf("初一") > -1){
					this.toggleshow = [false,true,false,false]
				}
				if(value.label.indexOf("初二") > -1){
					this.toggleshow = [false,true,true,false]
				}
				if(value.label.indexOf("初三") > -1){
					this.toggleshow = [false,true,true,true]
				}
				this.getalllist();
			},
			getgradelist:function(){
           		this.loadingShow = true;
           		var self = this;
            	let url = api.apidomain+'/tqes/web/tchStudent/getTchGradeSelect';
            	this.$http.post(url, {}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.gradelist = response.data.data
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00086',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
           	},
           	//根据年级id去获取添加的剩下的下拉框值
           	getalllist:function(){
           		this.loadingShow = true;
           		var self = this;
            	let url = api.apidomain+'/tqes/web/quaPerformance/getPerforByGradeId';
            	this.$http.post(url, {gradeId:this.gradeselect}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
//						self.gradelist = response.data.data
						self.highBaselist = response.data.data.highBase 
		                self.highThislist = response.data.data.highThis 
		                self.midBaselist = response.data.data.midBase 
		                self.midThislist = response.data.data.midThis 
		                self.midFirstBaselist = response.data.data.midFirstBase 
		                self.midSecondBaselist = response.data.data.midSecondBase
		                
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00087',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
           	},
           	addcalculation:function(){
           		if(this.gradeselectlabel == "" || this.calculationname == ""){
					this.$Message.error({
								content: "请完善信息后再提交",
								duration: 10,
								closable: true
							});	
					return;
				}
           		if(this.gradeselectlabel.indexOf("初") > -1){
           			var senddata = {
						"name":this.calculationname, 						//评价名称
						"gradeId":this.gradeselect,					//年级ID
						"baseExamId":this.midBase,				//基数考试ID
						"firstOverExamId":this.midFirstBase,			//初一下学期期末考试ID
						"secondOverExamId":this.midSecondBase,			//初二下学期期末考试ID
						"thisExamId":this.midThis,				//本次考试ID
					}
           		}else{
           			var senddata = {
						"name":this.calculationname, 						//评价名称
						"gradeId":this.gradeselect,					//年级ID
						"baseExamId":this.highBase,				//基数考试ID
						"thisExamId":this.highThis,				//本次考试ID
					}
           		}
           		this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/quaPerformance/algorithm';
//          	let url = 'http://192.168.43.196'+'/tqes/web/quaPerformance/algorithm';
            	this.$http.post(url,senddata).then(function(response) {
					if(response.data.success == true){
						self.$Message.success({
		                    content: '保存成功',
		                    duration: 10,
		                    closable: true
               			})
						self.$emit('chance')
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00088',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
           		
           	},
           	
           	
           	
           	//下面list数据
           	lookdetail:function(value,gradeid,name,gradeName,baseExamName,thisExamName,createTime){
				//保存评价id到sessionstorage
				setsessionstorage('performId',value);
				setsessionstorage('gradeId',gradeid);
				setsessionstorage('excelname',name);
				setsessionstorage('gradeName',gradeName);
				setsessionstorage('baseExamName',baseExamName);
				setsessionstorage('thisExamName',thisExamName);
				setsessionstorage('createTime',createTime);
        		this.$router.push({name:'querydetailedhigh'})
        	},
        	deldata:function(value){
				this.$Modal.confirm({
                    title: '确定删除',
                    content: '<p>确定删除这一条评价信息吗</p>',
                    onOk: () => {
                        this.$Message.loading({
		                    content: '正在删除中',
		                    duration: 0
		                });
		                
		                //删除年级的接口
		                var self = this;
		            	let url = api.apidomain+'/tqes/web/quaPerformance/deletePerformances';
		            	this.$http.post(url, {performId:value}).then(function(response) {
							if(response.data.success == true){
								self.$Message.destroy();
								self.$Message.success({
				                    content: '删除成功',
				                    duration: 10,
				                    closable: true
		               			})
								self.getcalculationlist();
				            }else if(response.data.success == false){
				            		self.$Message.error({
										content: response.data.msg,
										duration: 10,
										closable: true
									});
				            	}
							})
							.catch(function(error) {
								self.$Message.error({
									content: '系统发生错误：错误码00089',
									duration: 10,
									closable: true
								});
							});
		                
		                
		                
                    },
                    onCancel: () => {
//                      this.$Message.info('Clicked cancel');
                    }
                });
			},
			
			//应届往届改变后数据重新加载
			sessionCodeChange:function(){
           		if(this.sessionCode == "0"){
           			//判断如果是往届的话把数据清空
           			this.list = []
           			this.current = 1;
        			this.getcalculationlist()
           		}
           		if(this.sessionCode == "1"){
           			//判断如果是应届重新加载第一项数据
           			this.getcalculationlist()
           		}
           	},
			//改变年级后获取评价列表
			gradechange1:function(){
				this.current = 1;
        		this.getcalculationlist()
        	},
        	pageChange:function(value){
        		this.current = value;
        		this.getcalculationlist()
        	},
        	//获取往届的评价列表
        	getGraduateList:function(){
        		
        		this.current = 1;
        		this.getcalculationlist()
        	},
        	getcalculationlist:function(){
           		this.listshow = true;
           		let sessionroleid = getsessionstorage('roleid');
           		var self = this;
           		
           		if(this.sessionCode == "1"){
           			var senddata = {
	           			sessionCode:this.sessionCode,
	           			gradeId:this.gradeselect1,
	           			graduateYear:"",					//界别（往届）
	           			type:"High",
	           			roleId: sessionroleid,
						current:this.current,						//当前页数
						pageSize:"10"						//每页显示行数
	           		}
           		}else if(this.sessionCode == "0"){
           			var senddata = {
	           			sessionCode:this.sessionCode,
	           			gradeId:"",
	           			graduateYear:this.graduateYear,					//界别（往届）
	           			type:"High",
	           			roleId: sessionroleid,
						current:this.current,						//当前页数
						pageSize:"10"						//每页显示行数
	           		}
           		}
            	let url = api.apidomain+'/tqes/web/quaPerformance/getPerformancesByPage';
            	this.$http.post(url, senddata).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.list = response.data.data.items
						self.recordCount = response.data.data.recordCount
						if(self.list.length == 0){
							self.textinfo = "查询信息为空"
						}
						self.listshow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.listshow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00090',
							duration: 10,
							closable: true
						});
						self.listshow = false;
					});
           	},
           	getgradelist1:function(){
           		this.gradelistshow = true;
           		var self = this;
            	let url = api.apidomain+'/tqes/web/tchGrade/selectGrade';
            	this.$http.post(url, {"type":"High"}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.gradelist1 = response.data.data
						if(self.gradelist1.length > 0){
							self.gradeselect1 = self.gradelist1[0].value
							self.getcalculationlist();
						}
						
						self.gradelistshow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.gradelistshow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00091',
							duration: 10,
							closable: true
						});
						self.gradelistshow = false;
					});
           	},
        	exportexl:function(performanceId){
			
				if(performanceId){
					this.$Message.loading({
	                    content: '正在处理中',
	                    duration: 0
	                });
				
					var self = this;
	            	let url = api.apidomain+'/tqes/web/quaPerformance/exportPerformance';
	            	this.$http.post(url,{'performId':performanceId}).then(function(response) {
						if(response.data.success == true){
	//						////console.log(response.data.data)
							window.location.href = response.data.data;
							self.$Message.destroy()
		            }else if(response.data.success == false){
		            		self.$Message.destroy()
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});
		            	}
		            	
					})
					.catch(function(error) {
						self.$Message.destroy()
						self.$Message.error({
							content: '系统发生错误：错误码00092',
							duration: 10,
							closable: true
						});
					});
				}
			}
        	
		}
	}
</script>

<style lang="css" scoped>
	.changegray >>> .ivu-card-body{
		padding: 12px 15px;
		background-color: #f7f7f7;
	}
	.changegray >>> .alicon-down_light{
		font-weight: bold;
	}
</style>